import 'package:flutter/material.dart';
import 'package:qgchat/bloc/blocProvider.dart';
import 'package:qgchat/bloc/my/AnchorInfoBloc.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/models/anchorInfoModel.dart';
import 'package:qgchat/widgets/appbarCustom.dart';

/**
 * 时光价值页面
 * page时间价值
 */

class TimeValue extends StatefulWidget {
  @override
  _TimeValueState createState() => _TimeValueState();
}

class _TimeValueState extends State<TimeValue> {

  final blog = AnchorInfoBloc();


 int currentVal; // 当前价值

 _TimeValueState() {

   currentVal = 12;

 }

  void initState() {
    super.initState();

  }


//------------------------------------------------------------------------------

  /// appbar
  Widget appbar() {
    return AppbarCustom('时光价值', elevation: 0,);
  }

  /// 当前价值
  Widget currentValue() {
    return Container(
      child: Stack(
        alignment: AlignmentDirectional.center,
        children: <Widget>[
          /// BG
          Container(
            child: Image.asset('assets/images/timeValueBg.png'),
          ),
          Container(
            child: Column(
              children: <Widget>[
                Text(
                  '当前价值(金币/分钟)',
                  style: TextStyle(
                    fontSize: px(28),
                    color: col('ffffff'),
                  ),
                ),
                Text(
                  currentVal.toString(),
                  style: TextStyle(
                    fontSize: px(96),
                    color: col('ffffff'),
                    height: 1.4,
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

  /// 说明
  Widget explain() {
    return Container(
      width: w100(context),
      margin: EdgeInsets.only(top: px(30)),
      padding: EdgeInsets.symmetric(horizontal: px(30)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            '说明:',
            style: TextStyle(
              fontSize: px(28),
              color: col('909399'),
            ),
          ),
          Text(
            '30%归系统所有，可在“我的”——“我的钱包”中提现。',
            style: TextStyle(
              fontSize: px(28),
              color: col('303133'),
            ),
          ),
          Text(
            '修改时光价值请联系微信:84948994',
            style: TextStyle(
              fontSize: px(28),
              color: col('303133'),
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      bloc: blog,
      child: Scaffold(
        appBar: appbar(),
        body: Container(
          child: Column(
            children: <Widget>[
//              currentValue(),
              _CurrentValue(),
              explain(),
            ],
          ),
        ),
      ),
    );
  }
}

class _CurrentValue extends StatelessWidget {
  _CurrentValue({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final AnchorInfoBloc bloc = BlocProvider.of<AnchorInfoBloc>(context);

    String memberToken = state(context, 'user').info.memberToken;
//    print(state(context, 'user').info.memberToken);
    bloc.getAnchorInfo(memberToken);

    return StreamBuilder<AnchorInfoModel>(
      stream: bloc.outAnchorInfoStream,
      initialData: null,
      builder: (BuildContext context, AsyncSnapshot<AnchorInfoModel> snapshot) {
        if (snapshot.data != null) {
          return Container(
            child: Stack(
              alignment: AlignmentDirectional.center,
              children: <Widget>[
                /// BG
                Container(
                  child: Image.asset('assets/images/timeValueBg.png'),
                ),
                Container(
                  child: Column(
                    children: <Widget>[
                      Text(
                        '当前价值(金币/分钟)',
                        style: TextStyle(
                          fontSize: px(28),
                          color: col('ffffff'),
                        ),
                      ),
                      Text(
                        snapshot.data.timePrice.toString(),
                        style: TextStyle(
                          fontSize: px(96),
                          color: col('ffffff'),
                          height: 1.4,
                        ),
                      ),
                    ],
                  ),
                )
              ],
            ),
          );
        } else {
          return Container();
        }
      },
    );
  }
}

